home *** CD-ROM | disk | FTP | other *** search
- #include "main.h"
-
- extern int isBackground;
-
- static BitMap myClipBits;
- static RgnHandle myClipRgn;
- static int clipChanged = 0,
- isClip = 0,
- couldClip = 0,
- scrapCount,
- needsImport = -1;
-
- int couldPaste()
- {
- return( isClip || ( couldClip && needsImport ));
- }
-
- clearMyClip()
- {
- if( isClip ) {
- DisposPtr( myClipBits.baseAddr );
- SetEmptyRgn( myClipRgn );
- isClip = 0;
- ++clipChanged;
- }
- }
-
- setMyClip( source, maskRgn )
- BitMap *source;
- RgnHandle maskRgn;
- {
- clearMyClip();
- myClipBits = *source;
- ptrToPtr( &( myClipBits.baseAddr ));
- CopyRgn( maskRgn, myClipRgn );
- isClip = -1;
- needsImport = 0;
- ++clipChanged;
- }
-
- pasteClip( dest, maskRgn, force, dRect )
- BitMap *dest;
- RgnHandle maskRgn;
- Rect *dRect;
- {
- Rect sBounds, bounds;
- int dh, dv, result = 0;
-
- if( needsImport ) importScrap();
- if( isClip ) {
- if( force && rgnIsRect( maskRgn, &( dest->bounds ))) {
- CopyBig( &myClipBits, dest, &( myClipBits.bounds ), &( dest->bounds ), srcCopy, NULL );
- CopyRgn( myClipRgn, maskRgn );
- MapRgn( maskRgn, &( myClipBits.bounds ), &( dest->bounds ));
- } else {
- if( force ) DisposPtr( *dest->baseAddr );
- bounds = myClipBits.bounds;
- dh = ( dRect->right + dRect->left - bounds.right - bounds.left ) / 2;
- dv = ( dRect->bottom + dRect->top - bounds.bottom - bounds.top ) / 2;
- OffsetRect( &bounds, dh, dv );
- SectRect( &bounds, dRect, &bounds );
- sBounds = bounds;
- OffsetRect( &sBounds, -dh, -dv );
- setRectBits( dest, &bounds );
- CopyBig( &myClipBits, dest, &sBounds, &bounds, srcCopy, NULL );
- RectRgn( maskRgn, &sBounds );
- SectRgn( myClipRgn, maskRgn, maskRgn );
- OffsetRgn( maskRgn, dh, dv );
- }
- result = -1;
- }
- return( result );
- }
-
- initScrap()
- {
- myClipRgn = NewRgn();
- scrapCount = InfoScrap()->scrapCount - 1;
- setBadScrap();
- }
-
- setBadScrap()
- {
- long offset;
- int newCount;
-
- newCount = InfoScrap()->scrapCount;
- if( newCount != scrapCount ) {
- if( !needsImport ) {
- clearMyClip();
- clipChanged = 0;
- needsImport = -1;
- }
- scrapCount = newCount;
- couldClip = GetScrap( NULL, 'PICT', &offset ) >= 0;
- }
- }
-
- makeTempPort( tempBits, tempPort )
- BitMap *tempBits;
- GrafPtr tempPort;
- {
- OpenPort( tempPort );
- SetPortBits( tempBits );
- PortSize( tempBits->bounds.right - tempBits->bounds.left, tempBits->bounds.bottom - tempBits->bounds.top );
- MovePortTo( 0, 0 );
- SetOrigin( tempBits->bounds.left, tempBits->bounds.top );
- RectRgn( tempPort->visRgn, &tempBits->bounds );
- CopyRgn( tempPort->visRgn, tempPort->clipRgn );
- }
-
- importScrap()
- {
- GrafPort tempPort;
- Rect *bounds;
- PicHandle theScrap;
- GrafPtr savePort;
- long offset, errno;
-
- clearMyClip();
- if( couldClip ) {
- theScrap = ( PicHandle )NewHandle( 0L );
- errno = GetScrap( theScrap, 'PICT', &offset );
- if( errno >= 0 ) {
- bounds = &( **theScrap ).picFrame;
- setRectBits( &myClipBits, bounds );
- RectRgn( myClipRgn, bounds );
- GetPort( &savePort );
- makeTempPort( &myClipBits, &tempPort );
- DrawPicture( theScrap, bounds );
- SetPort( savePort );
- ClosePort( &tempPort );
- isClip = -1;
- } else if( errno != noTypeErr ) softPanic( errno, scrapPanic );
- DisposHandle( theScrap );
- clipChanged = 0;
- needsImport = 0;
- scrapCount = InfoScrap()->scrapCount;
- }
- }
-
- exportScrap()
- {
- GrafPort tempPort;
- BitMap tempBits;
- PicHandle thePict;
- GrafPtr savePort;
- Rect *bounds;
- long length;
-
- if( clipChanged ) ZeroScrap();
- if( isClip && clipChanged ) {
- GetPort( &savePort );
- makeTempPort( &myClipBits, &tempPort );
- tempBits.rowBytes = 0;
- tempBits.bounds.top = tempBits.bounds.left = 0;
- tempBits.bounds.bottom = tempBits.bounds.right = 0;
- tempBits.baseAddr = NewPtr( 0L );
- SetPortBits( &tempBits );
- bounds = &myClipBits.bounds;
- thePict = OpenPicture( bounds );
- CopyBig( &myClipBits, &tempBits, bounds, bounds, srcCopy, myClipRgn );
- ClosePicture();
- length = GetHandleSize( thePict );
- HLock( thePict );
- PutScrap( length, 'PICT', *thePict );
- KillPicture( thePict );
- SetPort( savePort );
- ClosePort( &tempPort );
- DisposPtr( tempBits.baseAddr );
- }
- clipChanged = 0;
- needsImport = 0;
- scrapCount = InfoScrap()->scrapCount;
- }
-
-
- doEdClear( theData )
- dataPtr theData;
- {
- int needsDraw = 0;
-
- if( theData->isSelect ) {
- if( theData->selActive ) --isBackground;
- theData->isSelect = 0;
- theData->selActive = 0;
- DisposPtr( theData->selBits.baseAddr );
- SetEmptyRgn( theData->selRgn );
- needsDraw = bitsBadData;
- }
- return( needsDraw );
- }
-
- doEdPaste( theData )
- dataPtr theData;
- {
- int needsDraw = 0;
-
- if( couldPaste() && pasteClip( &( theData->selBits ), theData->selRgn, theData->isSelect, &( theData->dataRect ))) {
- if( !theData->isSelect ) {
- ++isBackground;
- theData->isSelect = -1;
- theData->selActive = -1;
- needsDraw |= bitsBadAnts;
- }
- needsDraw |= bitsBadSel;
- }
- return( needsDraw );
- }
-
-